package com.clstu.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapExercise {
    public static void main(String[] args) {
          Employee[] employees = new Employee[3];
          employees[0]=new Employee("jack",1,18002);
          employees[1]=new Employee("mary",2,17002);
          employees[2]=new Employee("john",3,18000);
        Map map= new HashMap();
        for (int i = 0; i < 3; i++) {
            map.put(employees[i].getId(),employees[i]);
        }
        Set set = map.entrySet();
        for (Object o:set) {
            Map.Entry entry=(Map.Entry) o;
            //if(((Employee) (entry.getValue())).getSalary()>=18000)//这种代码最好写成两步，便于后面自己看的时候理解
            Employee employee=(Employee) entry.getValue();
            if (employee.getSalary()>=18000)
                System.out.println(entry.getValue());
        }
        System.out.println("==========");
        Collection values=map.values();
        for (Object o:values
             ) {
            Employee employee=(Employee) o;
            if (employee.getSalary()>=18000)
                System.out.println(employee);
        }


    }
}
class Employee{
    private String name;
    private int id;
    private double salary;

    public Employee(String name, int id, double salary) {
        this.name = name;
        this.id = id;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return
                "name='" + name + '\'' +
                ", id=" + id +
                ", salary=" + salary ;
    }
}